/* ====================================== toast  ====================================== */
import { notification } from 'antd'

const { $Lazy, $fn } = window
// ===================================================================== Component
const Button 	= $Lazy.load(()=>import('@antd/button'))
// ===================================================================== Confirm
const Notice = ({ title='提示', msg, type='warning', placement, btn, noClose, duration, closeIcon, download_url }) => {
	const key = `notice${Date.now()}`
	const option = {
		message: title, description: msg, placement, duration, closeIcon, key,
	}
	if($fn.hasObject(btn)){
		option['btn'] = <Button label={btn.label || '确认收到'} onClick={() => {
			btn.onClick && btn.onClick()
			if (download_url) window.open(download_url)
			notification.close(key)
		}} />
	}
	if(noClose === true){
		option['closeIcon'] = <></>
	}
	notification[type](option)
}
const Index = {
	warning: (msg, title, option) => Notice({ msg, title, ...option }),
	error: (msg, title, option) => Notice({ msg, title, type:'error', ...option }),
	info: (msg, title, option) => Notice({ msg, title, type:'info', ...option }),
	success: (msg, title, option) => Notice({ msg, title, type:'success', ...option })
}
export default Index